﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_ChiTietHoaDon : System.Web.UI.Page
{
    TiemPhongDataContext db = new TiemPhongDataContext();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        // lay ma hoa don MaHD
        string _maHD = Request.QueryString["id"].ToString();
        if (!String.IsNullOrEmpty(_maHD))
        {
            loadDataListView(_maHD);

        }
    }
    protected void loadDataListView(string MHD)
    {
        var ctHoaDon = from u in db.ChiTietHoaDons
                       where u.MaHD == MHD
                       select new
                       {
                           u.MaCTHD,
                           u.MaVC,
                           u.SoLuong,
                           u.ThanhTien
                       };
        if (ctHoaDon == null)
        {
            lableNull.Enabled = true;
        }
        ListViewCTHoaDon.DataSource = ctHoaDon;
        ListViewCTHoaDon.DataBind();
        cbMaHD.SelectedValue = MHD;
        loadComboMaHD();
        loadComboMaVC();
        txtMaCTHD.Text = loadIDCTHD();
    }
    // tai danh sach ma Hoa Don
    protected void loadComboMaHD()
    {
        var cb1 = from v in db.HoaDons
                  select v;
        cbMaHD.DataValueField = "MaHD";
        cbMaHD.DataTextField = "MaHD";
        cbMaHD.DataSource = cb1.ToList();
        cbMaHD.DataBind();
        cbMaHD.Items.Insert(0, "--Select--");        
    }
    // tai danh sach ma Vac xin
    protected void loadComboMaVC()
    {
        var cb2 = from k in db.Vac_xins select k;
        cbMaVC.DataValueField = "MaVC";
        cbMaVC.DataTextField = "MaVC";
        cbMaVC.DataSource = cb2.ToList();
        cbMaVC.DataBind();
        cbMaVC.Items.Insert(0, "--Select--");
    }
    protected string loadIDCTHD()
    {
        string cid = "";
        var slid = (from u in db.ChiTietHoaDons select u.MaCTHD).Count() + 1;
        cid = slid.ToString();
        cid = "CTHD" + cid;
        return cid;
    }
    protected void btnThem_Click(object sender, EventArgs e)
    {

    }
    protected void btnCapNhatSua_Click(object sender, EventArgs e)
    {
        //try 
        //{
        //}
        //catch()
        //{
        //}
    }
}